package com.zhbit.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MyInterceptor extends AbstractInterceptor{

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext context=ActionContext.getContext();
		Map<String,Object> session = context.getSession();
		if(session.get("loginInfo")!=null){
			String result=invocation.invoke();
			return result;
		}else{
			return "login";
		}
	}

//	public void init(){
//		System.out.println("开始执行：\t");
//	}
//	@Override
//	public String intercept(ActionInvocation arg) throws Exception {
//		// TODO Auto-generated method stub
//		String resuit="";
//		System.out.println("执行中：。。。");
//		String user = (String)ActionContext.getContext().getSession().get("user");
//		if(user==""){
//			System.out.println("非法访问....");
//			return "error_login";
//		}
//		resuit = arg.invoke();
//		System.out.println("登录成功："+user);
//		return resuit;
////		Map session=arg.getInvocationContext().getSession();
////		String uname=(String)session.get("username");
////		
////		if(uname!=null&&!uname.equals("username")){
////			return arg.invoke();
////		}else{
////			session.put("error_Msg", "您还未登录");
////			return Action.ERROR;
////		}
//	}
//	public void destroy(){
//		System.out.println("结束：\t==");
//	}
}
